import time

import allure

from base_config import HOST
from pages.base_page import BasePage
from pages.elements import Elements
from pages.reg_success_page import RegSuccessPage
from utils.log_manager import my_logger
class RegPage(BasePage):

    url = HOST+'sign-in'

    def open_page(self):
        my_logger.logger.debug("打开注册页:{}",self.url)
        self.open(self.url)


    def reg_by_phone(self,name,phone,passwd,re_passwd):
        allure.step("输入昵称")
        self.input_data(Elements.INPUT_NAME,name)
        allure.step("输入手机号")
        self.input_data(Elements.INPUT_PHONE,phone)
        allure.step("输入密码")
        self.input_data(Elements.INPUT_PASSWORD1,passwd)
        allure.step("确认密码")
        self.input_data(Elements.INPUT_PASSWORD2,re_passwd)
        allure.step("点击登录按钮")
        self.click_element(Elements.REG_BTN)
        return RegSuccessPage()

    def reg_by_email(self,name,phone,passwd,re_passwd):
        self.click_element(self.Email注册['type'],self.Email注册['value'])
        self.input_data(self.名字['type'],self.名字['value'],name)
        self.input_data(self.电子邮箱['type'],self.电子邮箱['value'],phone)
        self.input_data(self.输入密码['type'],self.输入密码['value'],passwd)
        self.input_data(self.确认密码['type'],self.确认密码['value'],re_passwd)
        self.click_element(self.隐私条款['type'],self.隐私条款['value'])
        self.click_element(self.继续按钮['type'],self.继续按钮['value'])
        return RegSuccessPage()

    def is_reg_success(self):
        time.sleep(2)
        try:
            current_url = self.driver.current_url
            my_logger.logger.info("注册后跳转的地址:{}",current_url)
            if 'login' in current_url:
                return True
        except:
            return False
        return False

